package com.baor.controller;

import com.baor.service.MenuService;
import com.baor.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController

@RequestMapping(value = "/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @RequestMapping("menuList")
    public AjaxResult<?> menuList(){
        return menuService.menuList2();
    }

    @RequestMapping("menu")
    public AjaxResult<?> menu(Integer userId){
        return menuService.menu(userId);
    }

    @RequestMapping("allMenu")
    public AjaxResult<?> allMenu(@RequestBody Map<String,Object> param){
       if(param.get("pageIndex") != null){
           int pageindex = (int) param.get("pageIndex");
           int pagesize = (int) param.get("pageSize");
           param.put("pageIndex", (pageindex - 1) * pagesize);
       }
        System.out.println(param);
       return menuService.allMenu(param);
    }

    @RequestMapping("searchMenu")
    public AjaxResult<?> searchMenu(@RequestBody Map<String,Object> param){
        int pageindex = (int) param.get("pageIndex");
        int pagesize = (int) param.get("pageSize");
        param.put("pageIndex", (pageindex - 1) * pagesize);
        return menuService.allMenu(param);
    }

    @RequestMapping("delete")
    public AjaxResult<?> delete(int menuId){
        return menuService.delete(menuId);
    }

    @RequestMapping("menuInfo")
    public AjaxResult<?> menuInfo(int menuId){
        return menuService.menuInfo(menuId);
    }

    @RequestMapping("updateInfo")
    public AjaxResult<?> updateInfo(int menuId){
        return menuService.updateInfo(menuId);
    }

    @RequestMapping("update")
    public AjaxResult<?> update(@RequestBody Map<String,Object> param){
        return menuService.update(param);
    }

    @RequestMapping("addInfo")
    public AjaxResult<?> addInfo(){
        return menuService.addInfo();
    }

    @RequestMapping("insertMenu")
    public AjaxResult<?> insertMenu(@RequestBody Map<String,Object> param){
        return menuService.insertMenu(param);
    }



}
